<%--
  Created by IntelliJ IDEA.
  User: redmi
  Date: 2023/12/3
  Time: 11:00
  To change this template use File | Settings | File Templates.
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<html>
<head>
  <link href="css/login.css" type="text/css" rel="stylesheet">
  <meta charset="UTF-8">
  <title>学生信息管理系统-登录界面</title>
    <script>
        function showMessage(message) {
            alert(message);
        }
    </script>
</head>
<body>
<form action="/demo2_war_exploded/loginServlet" method="post">
  <div class="content">
    <div class="wrap">
      <div class="login-box">
        <div class="login-frame">
          <h2>
            用户登录 <a href="register.jsp"> 立即注册</a>
          </h2>
          <div class=item>
            <input type="text" name="UID" placeholder="用户名">
          </div>
          <div class=item>
            <input type="password" name="upwd" placeholder="密码">
          </div>
          <input type="submit" class="login-btn" value="登 录">
          <div class=item1>
            <a href="UpdateLoginPwd.jsp"> 修改密码</a>
            <a	onclick="showMessage('请联系上级办完离职手续后进行后台删除，谢谢！');"> 注销用户</a>
            <div class="power-by">Power by 阮增炜</div>

          </div>

      <%
        Cookie[] cookies = request.getCookies();
        if (cookies != null) {
          for (Cookie cookie : cookies) {
            if (cookie.getName().equals("username")) {
              String username = cookie.getValue();
              if (username.equals("cookie登录")){
                session.setAttribute("user", "cookie登录");
                request.getSession().setMaxInactiveInterval(300);
                response.sendRedirect("home.jsp");
              }
            }
          }
        }
            String error = (String) request.getAttribute("error");
            String error0 = (String) request.getAttribute("error0");
            String error1 = (String) request.getAttribute("error1");
            if (error != null) {
              if (error.equals("loginError")) {
                out.println("<script>showMessage('用户名或密码错误！登录失败！');</script>");
              } else if (error.equals("nologinError")) {
                session = request.getSession();
                session.setAttribute("user",request.getParameter("UID") );
                request.getSession().setMaxInactiveInterval(300);
                Cookie cookie = new Cookie("username", "cookie登录");
                cookie.setMaxAge(60*50);
                response.addCookie(cookie);
                response.sendRedirect("home.jsp");
              }
            }

            if (error0 != null) {
              if (error0.equals("loginError")) {
                out.println("用户名或密码错误！修改失败！");
              } else if (error0.equals("nologinError")) {
                if (error1 != null) {
                  if (error1.equals("noupdateError")) {
                    out.println("密码修改成功！");
                  }
                }
              }
            }




      %>
        </div>
      </div>
    </div>
  </div>
</form>

</body>
</html>
